package com.zenghus.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class LoggerProxy implements InvocationHandler{

    private Object obj;
    LoggerProxy(Object objs){
        this.obj=objs;
    }

    public Object newProxyInstance(){
        return Proxy.newProxyInstance(obj.getClass().getClassLoader(),obj.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Exception{
        System.out.println("开始调用"+method.getName()+"方法");
        Object o=method.invoke(obj,args);
        System.out.println(method.getName()+"方法调用结束");
        return o;
    }
}
